﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;

using YLClient.Util;

using System.Threading;
using System.Threading.Tasks;
using System.Windows.Threading;

namespace YLClient.Froms
{
    /// <summary>
    /// Interaction logic for NewItem.xaml
    /// </summary>
    public partial class NewItem : Window
    {
        TemplateManager tm;
        private void initialUI()
        {
            //获取模板列表
            tm = TemplateManager.GetTemplateManager();
            foreach (var t in tm.templates)
            {
                cmbTemplateName.Items.Add(t.mTemplateDetial.mName);
            }
            cmbTemplateName.SelectedIndex = 0;
        }
        /// <summary>
        /// 判断信息填写完善
        /// </summary>
        /// <returns></returns>
        private bool checkAllValue()
        {
            foreach (dynamic item in lstRequireValues.Items)
            {
                if (item.IsSetValue == false)
                    return false;
            }
            foreach (dynamic item in lstFiles.Items)
            {
                if (item.IsSetValue == false)
                    return false;
            }
            return true;
        }

        private void cmbTemplateName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var crrtname = cmbTemplateName.SelectedValue.ToString();
            var crrt = tm.templates.Where(t => t.mTemplateDetial.mName == crrtname).First();
            //初始化必填参数
            lstRequireValues.Items.Clear();
            foreach (var item in crrt.mTemplateDetial.mRequireValues.mItem)
            {
                var ra = new UserControls.TemplateControls.RequireArgument(item);
                lstRequireValues.Items.Add(ra);
            }
            //初始化比传文件
            lstFiles.Items.Clear();
            foreach (var item in crrt.mTemplateDetial.mRequireAttchments.mItem)
            {
                var ra = new UserControls.TemplateControls.RequireAttachment(item);
                lstFiles.Items.Add(ra);
            }
        }
    }
}
